<?php
#declare (strict_types=1);
/**
 * @Description:
 * @Author: Chern
 * @Date: 2023/7/10
 * @Time: 14:13
 */
namespace app\validate;

use think\Validate;

class User extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'id'=>['require','integer'],
        'nickname'=>['require'],
        'username' =>['require'],
//        'password'=>['require'],
        'describe'=>['require'],
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [
        'id.require'=>'id不能为空',
//        'id.integer'=>'id必须为整数',
        'nickname.require'=>'姓名不能为空',
        'username.require'=>'用户名不能为空',
        'create_date.require'=>'创建时间不能为空',
        'describe.require'=>'描述不能为空',
        'password.require'=>'密码不能为空',
        'password.number'=>'默认密码错误',
        'department_id.require'=>'所属公司部门不能为空',
        'level_id.require'=>'角色名称不能为空',
        'hire_date.require'=>'入职时间不能为空',
        'mobile.require'=>'手机号码不能为空',
        'level_name.require'=>'职位名称不能为空',
    ];

    /**
     * 新增数据控制验证字段
     */
    protected $scene = [
        'add'=>['nickname','username','create_date','describe'],
    ];

    /**
     * 添加用户使用
     */
    public function sceneAddUser()
    {
        return $this->only(['nickname','username','password','department_id','level_id'])
            ->append('password','require|eq:123456')
            ->append('department_id','require|number')
            ->append('level_id','require|number');
//            ->append('hire_date','require')
//            ->append('mobile','require|mobile');
    }

    /**
     * 添加用户使用
     */
    public function sceneEditUser()
    {
        return $this->only(['id','nickname','username','password','department_id','level_id','hire_date','mobile'])
            ->append('password','require|eq:123456')
            ->append('department_id','require|number')
            ->append('department_id','require|number')
            ->append('level_id','require|number')
            ->append('hire_date','require')
            ->append('mobile','require|mobile');
    }

    /**
     * 启用|禁用规则
     */

    public function sceneDEUser()
    {

        return $this->only(['id','is_k'])
            ->append('is_k','require|in:0,1')
            ->append('id','require');
    }

    /**
     * 修改职位昵称
     */
    public function sceneEditName()
    {
        return $this->only(['level_name','id'])
            ->append('level_name','require');
    }

    /**
     * 数据交接验证
     */
    public function sceneDataHandOver()
    {
        return $this->only(['handover_data','get_uid','push_uid','get_org'])
            ->append('handover_data|交接数据类型','require')
            ->append('get_uid|接收人','require')
            ->append('get_org|接收人部门','require')
            ->append('push_uid|转出人','require');
    }

}
